package com.alibaba.algo.components.yapi;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.algo.components.yapi.entity.CatMenu;
import com.alibaba.algo.components.yapi.entity.InterfaceInfo;
import com.alibaba.algo.components.yapi.entity.Project;

/**
 * @Description: yapi 数据缓存管理器
 * @author: malin
 * @date: 2020-12-1 17:08:41
 */
public class YapiDataCacheManger {

	private static List<CatMenu> catMenuList = new ArrayList<CatMenu>(20);
	private static List<InterfaceInfo> interfaceList = new ArrayList<InterfaceInfo>(100);
	private static Project project = null;

	/**
	 * @Description: 新增接口分类（菜单）
	 * @author: malin
	 * @date: 2020-12-1 17:12:29
	 */
	public static void addCatMenu(CatMenu catMenu) {
		YapiDataCacheManger.catMenuList.add(catMenu);
	}

	/**
	 * @Description: 批量新增接口分类（菜单）
	 * @author: malin
	 * @date: 2020-12-1 17:12:29
	 */
	public static void addCatMenu(List<CatMenu> catMenuList) {
		YapiDataCacheManger.catMenuList.addAll(catMenuList);
	}

	/**
	 * @Description: 根据菜单名称获取菜单详情
	 * @author: malin
	 * @date: 2020-12-1 17:16:40
	 */
	public static CatMenu getCatMenu(String name) {
		for (CatMenu catMenu : catMenuList) {
			if (catMenu.getName().equals(name)) {
				return catMenu;
			}
		}
		return null;
	}

	public static void setProject(Project project) {
		YapiDataCacheManger.project = project;
	}

	public static Project getProject() {
		return YapiDataCacheManger.project;
	}

	/**
	 * @Description: 增加接口列表
	 * @author: malin
	 * @date: 2020-12-9 10:22:01
	 */
	public static void addInterfaceInfoList(List<InterfaceInfo> interfaceInfoList) {
		YapiDataCacheManger.interfaceList.addAll(interfaceInfoList);
	}

	/**
	 * @Description: 获取接口
	 * @author: malin
	 * @date: 2020-12-9 10:44:43
	 */
	public static InterfaceInfo getInterfaceInfo(String path, Integer catid) {
		for (InterfaceInfo interfaceInfo : interfaceList) {
			if (interfaceInfo.getCatid().compareTo(catid) == 0 && interfaceInfo.getPath().equals(path)) {
				return interfaceInfo;
			}
		}
		return null;
	}

}
